﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NLog;

namespace TfsGiggle.Core
{
    /// <summary>
    /// Get an eventid to the eventlog
    /// </summary>
    public class LoggerWithEventId:Logger
    {
        /// <summary>
        /// ctor
        /// </summary>
        public LoggerWithEventId() { }

        /// <summary>
        /// Log this exception with this eventid
        /// </summary>
        /// <param name="eventId"></param>
        /// <param name="message"></param>
        /// <param name="ex"></param>
        public void ErrorExceptionWithEventId(int eventId, string message, Exception ex)
        {
            if (IsErrorEnabled)
            {
                var logEventInfo = new LogEventInfo(LogLevel.Error, Name, message);
                logEventInfo.Exception = ex;
                logEventInfo.Properties["EventId"] = eventId;
                base.Log(typeof(LoggerWithEventId), logEventInfo);
            }
        }

        /// <summary>
        /// Log this fatal with this exception
        /// </summary>
        /// <param name="eventId"></param>
        /// <param name="message"></param>
        /// <param name="ex"></param>
        public void FatalExceptionWithEventId(int eventId, string message, Exception ex)
        {
            if (IsFatalEnabled)
            {
                var logEventInfo = new LogEventInfo(LogLevel.Fatal, Name, message);
                logEventInfo.Exception = ex;
                logEventInfo.Properties["EventId"] = eventId;
                base.Log(typeof(LoggerWithEventId), logEventInfo);
            }
        }
    }
}
